package com.baizhi.controller;

import com.baizhi.dto.PageDTO;
import com.baizhi.dto.PageDTOs;
import com.baizhi.entity.Category;
import com.baizhi.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("category")
public class CategoryController {
    private static final Logger log = LoggerFactory.getLogger(CategoryController.class);
    @Resource
    CategoryService categoryService;
    @RequestMapping("queryOnePage")
    public HashMap<String, Object> queryOnePage(@RequestBody PageDTO pageDTO){
        log.info("当前页:{}",pageDTO.getPage());
        log.info("每页几行:{}",pageDTO.getPageSize());
        HashMap<String, Object> map = categoryService.queryOnePage(pageDTO);

        return map;
    }
    @RequestMapping("delete")
    public HashMap<String, Object> delete(@RequestBody Category category){
        log.info("删除的信息:{}",category);
        HashMap<String, Object> map = categoryService.delete(category);
        return map;
    }
    @RequestMapping("add")
    public HashMap<String,Object> add(@RequestBody Category category){
        log.info("添加的信息:{}",category);
        HashMap<String, Object> map = categoryService.add(category);
        return map;
    }
    @RequestMapping("queryById")
    public Category queryById(String id){
        log.info("查询的id:{}",id);
        Category category = categoryService.queryById(id);
        return category;
    }
    @RequestMapping("update")
    public HashMap<String, Object> update(@RequestBody Category category){
        log.info("修改的对象:{}",category);
        HashMap<String, Object> map = categoryService.update(category);
        return map;
    }
    @RequestMapping("queryTwoPage")
    public HashMap<String, Object> queryTwoPage(@RequestBody PageDTOs pageDTOs){
        log.info("分页二级类别:{}",pageDTOs);
        HashMap<String, Object> map = categoryService.queryTwoPage(pageDTOs);
        return map;
    }
    @RequestMapping("queryByLevelsCategory")
    public List<Category> queryByLevelsCategory(Integer levels){
        log.info("接受的数据:{}",levels);

        return categoryService.queryByLevelsCategory(levels);
    }
}
